package org.groupg.project.processManager;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

// 简单的事件总线
public class EventBus {
    private static final List<Consumer<Object>> subscribers = new CopyOnWriteArrayList<>();

    public static void subscribe(Consumer<Object> subscriber) {
        subscribers.add(subscriber);
    }

    public static void publish(Object event) {
        subscribers.forEach(subscriber -> {
            try {
                subscriber.accept(event);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}